#pragma once

/* 输出一段地址的内容 */
#include <compl.h>

// DECL_MEFF(int, md_print, (const char *fmt, ...))
/* 泛型dump */
SAI void __memdump_os(void *start, size_t size, dbgprint_func_t *md_print){
	size_t i;
	word_t *parr=(word_t *)start;
	word_t j;
	md_print("----------md----------\n");
	for (i = 0, j = 0; i < size;
		i += 4 * sizeof(word_t), j++)
		md_print("[%lx] %lx%lx %lx%lx\n", (size_t)&parr[j],
		parr[j], parr[j+1], parr[j+2], parr[j+3]);
	md_print("----------md----------\n");
}

SAI void __memdump_hword(void *arr, size_t size, dbgprint_func_t *md_print){
	md_print("----------md----------\n");
	for (word_t i = 0; i < size / sizeof(hword_t) ; i += 4)
	{
		md_print("[0x%lx] %08lx %08lx %08lx %08lx\n", &(((hword_t *)arr)[i]), ((hword_t *)arr)[i], ((hword_t *)arr)[i + 1], ((hword_t *)arr)[i + 2], ((hword_t *)arr)[i + 3]);
	}
	md_print("----------md--------\n");
}

SAI void __memdump_word(void *arr, size_t size, dbgprint_func_t *md_print){
	md_print("----------md----------\n");
	for (word_t i = 0; i < size / sizeof(word_t) ; i += 4)
	{
		md_print("[0x%lx] %016lx %016lx %016lx %016lx\n", &(((word_t *)arr)[i]), ((word_t *)arr)[i], ((word_t *)arr)[i + 1], ((word_t *)arr)[i + 2], ((word_t *)arr)[i + 3]);
	}
	md_print("----------md--------\n");
}

#define DEF_MEMDUMP(name, printfunc)																		\
SAI void name##dump_os(void *start, size_t size){ __memdump_os(start, size, printfunc); }		 \
SAI void name##dump_hword(void *start, size_t size){ __memdump_hword(start, size, printfunc); }   \
SAI void name##dump_word(void *start, size_t size){ __memdump_word(start, size, printfunc); }
